
const config = require('../config');
const { bech32 } = require('bech32');

const TokenMessenger = require('../scObjs/TokenMessager');

const web3 = require('web3')

const {
    eth_caller_wallet,
    fn_noble_caller,
    fn_noble_receipter
} = require('../wallet');

const address_noble_to_eth= (nobleAddress) => {

    const mintRecipient = bech32.fromWords(bech32.decode(nobleAddress).words);
    console.log("mintRecipient: ", mintRecipient)

    const mintRecipientBytes = new Uint8Array(32);
    mintRecipientBytes.set(mintRecipient, 32 - mintRecipient.length);
    const mintRecipientHex = web3.utils.bytesToHex(mintRecipientBytes);

    return mintRecipientHex;
}
const run =  async ()=>{

    const admin = eth_caller_wallet;

    const noble_caller_wallet = await fn_noble_caller();
    const [caller_account] = await noble_caller_wallet.getAccounts();
    const caller_nobleAddress = caller_account.address;

    const noble_receipter_wallet = await fn_noble_receipter();
    const [receipter_account] = await noble_receipter_wallet.getAccounts();

    const receipter_nobleAddress = receipter_account.address;

    const receiptHex = address_noble_to_eth(receipter_nobleAddress);
    const callerHex = address_noble_to_eth(caller_nobleAddress);


    const tokenMessager = new TokenMessenger(config.goerli.urls[0], config.goerli.scAddr.tokenMessenger_ScAddr);

    const amount = 1000000;  //1 usdc
    const usdc_scAddr = config.goerli.scAddr.USDC_ScAddr;
    const destinationDomain = 4;

    let rt = await tokenMessager.depositForBurnWithCaller(admin, amount,destinationDomain, receiptHex, usdc_scAddr, callerHex);
    console.log('1 -- rt: ', rt)






}

run();

/*
* blockHash: '0x7139f30b25a131f00719a4e6e733a901899e92c63c2238de01e0f0657ce78d01',
  transactionHash: '0x06681916b8fb06e3759e76511c798c78c8053b7c6fe33aa149736dda708448a2',

* */